#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>
#include <unistd.h>



#define FILE	"/dev/driver_test"		   // 设备文件路径


char buf[100]={0};

int main(void)
{
	int fd = -1;
	int i = 0;
	
	fd = open(FILE, O_RDWR);   // 执行驱动结构器open 
	if (fd < 0)
	{
		printf("open %s error.\n", FILE);
		return -1;
	}
	printf("open %s success..\n", FILE);



// 测试    copy_from_user 、 copy_to_user 
   	 write(fd, "on", 2);   // 读写文件 --》 调用file_operator的 .write 对应函数
     read(fd,buf,100);    
     printf("app, read content is = %s \n", buf);
	 sleep(5);





  // 在应用中输入 on 打开  led 
	// 在应用中输入 off 关闭 led 
  while(0){
    printf("%s\n", "请输入状态:");
  	memset(buf,0,sizeof(buf));
    scanf("%s",buf);
    if(   strcmp(buf,"on") ==0 ){
       write(fd, "1", 1); 
    }else if(  strcmp(buf,"off") == 0 ){
       write(fd, "0", 1); 
    }else if( strcmp(buf,"quit" )==0) {
    	break;
    }
  }


    while(0){
    printf("%s\n", "请输入状态:");
  	memset(buf,0,sizeof(buf));
    scanf("%s",buf);
    if(   strcmp(buf,"on") ==0 ){
      write(fd, "on", 2); 
    }else if(  strcmp(buf,"off") == 0 ){
       write(fd, "off", 3); 
    }else if( strcmp(buf,"quit" )==0) {
    	break;
    }
  }

	// 关闭文件, 执行驱动结构体的 test_chrdev_release
	close(fd);


	return 0;
 }
